package com.fu.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.annotation.WebListener;

/**
 * @author 付大大
 * @description
 * @create 2021-01-26 11:44
 */
//@WebListener
public class ServletContextAttributeListenerDemo implements ServletContextAttributeListener {
    @Override
    public void attributeAdded(ServletContextAttributeEvent scae) {
        System.out.println("监听倒了属性的添加");

        ServletContext servletContext = scae.getServletContext();
        Object username = servletContext.getAttribute("username");
        System.out.println(username);
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent scae) {
        System.out.println("监听倒了属性的替换");

        ServletContext servletContext = scae.getServletContext();
        Object username = servletContext.getAttribute("username");
        System.out.println(username);

    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent scae) {
        System.out.println("监听倒了属性的移除");
        ServletContext servletContext = scae.getServletContext();
        Object username = servletContext.getAttribute("username");
        System.out.println(username);
    }
}
